﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;//Input & Output
using Microsoft.Win32;//RegistryKey

namespace GoatClubPlus
{
    public partial class LogoForm : Form
    {
        public LogoForm()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            this.Hide();
            LoginForm dlg = new LoginForm();
            dlg.ShowDialog();
        }

        private void LogoForm_Load(object sender, EventArgs e)
        {
            //判断注册表是否存在
            string[] subkeyNames; string firstrun = "true";
            RegistryKey hkml = Registry.LocalMachine;
            RegistryKey software = hkml.OpenSubKey("SOFTWARE");
            subkeyNames = software.GetSubKeyNames(); 
            //取得该项下所有子项的名称的序列，并传递给预定的数组中
            foreach (string keyName in subkeyNames) //遍历整个数组 
            {
                if (keyName == "GoatClub") //判断子项的名称
                {
                    firstrun = "false";
                    hkml.Close(); software.Close();
                    timer1.Enabled = true;
                }
            }
            if (firstrun == "true")
            {
                software.Close();
                RegistryKey key = hkml.CreateSubKey("SOFTWARE\\GoatClub");//不存在则创建
                RegistryKey creat = hkml.OpenSubKey("software\\GoatClub", true); //该项必须已存在
                creat.SetValue("Name", ""); creat.SetValue("Avatar", ""); creat.SetValue("Password", "");
                creat.SetValue("RPW", "false"); creat.SetValue("firstrun", "false");
                creat.Close();
                key.Close();
                hkml.Close();
                timer1.Enabled = true;
            }
        }
    }
}
